package com.xquant.trade.account.service.impl;

import com.github.pagehelper.PageInfo;
import com.xquant.trade.account.entity.Counterparty;
import com.xquant.trade.account.mapper.CounterpartyMapper;
import com.xquant.trade.account.service.CounterpartyService;
import com.xquant.trade.trade.entity.PartyStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @Author yunnuo.yang
 * @Date 2020/10/16 11:21
 * @Description
 **/
@Service(CounterpartyService.BEAN_NAME)
public class CounterpartyServiceImpl implements CounterpartyService {

    @Autowired
    private CounterpartyMapper counterpartyMapper;
    String fold = "counterparty";

    @Override
    public PageInfo<Counterparty> queryCounterpartyByPage(Map<String, Object> param) {
        List<Counterparty> list = counterpartyMapper.queryCounterpartyByPage(param);
        return new PageInfo<>(list);
    }

    @Override
    public PageInfo<Counterparty> queryCounterpartyCombox(Map<String, Object> param) {
        List<Counterparty> list = counterpartyMapper.queryCounterpartyCombox(param);
        return new PageInfo<>(list);
    }

    @Override
    public List<Counterparty> queryCounterparty(Map<String, Object> param) {
        List<Counterparty> list = counterpartyMapper.queryCounterparty(param);
        return list;
    }

    @Override
    public List<Counterparty> queryByPartyId(Map<String, Object> param) {
        List<Counterparty> list = counterpartyMapper.queryByPartyId(param);
        return list;
    }

    @Override
    public void insertCounterparty(Counterparty cp) {
        cp.setStatus(PartyStatus.NEW);
        counterpartyMapper.insertCounterparty(cp);
    }

    @Override
    public void updateCounterparty(Counterparty cp) {
        counterpartyMapper.updateCounterparty(cp);
    }

    @Override
    public void updateCounterpartyStatus(Counterparty cp) {
        counterpartyMapper.updateCounterpartyStatus(cp);
    }

    @Override
    public List queryCounterpartyTrade(Counterparty cp) {
        return counterpartyMapper.queryCounterpartyTrade(cp);
    }

    @Override
    public boolean checkPartyName(Counterparty cp) {
        Counterparty counterparty = counterpartyMapper.checkPartyName(cp.getPartyName());
        if (counterparty==null){
            return true;
        }else {
            if (counterparty.getPartyId().equals(cp.getPartyId())){
                return true;
            }else {
                return false;
            }
        }
    }

    @Override
    public Counterparty queryByPartyName(Counterparty cp) {
        return counterpartyMapper.checkPartyName(cp.getPartyName());
    }

    @Override
    public void deleteCounterparty(Counterparty cp) {
        counterpartyMapper.deleteCounterparty(cp);
    }

}
